#include "light_gate.h"


LightGateInstance *LightGateInit(uint16_t GPIO_Pin)//因为3pin可配置io口只在gpioc上（c板中），所以不用传入gpio组
{
    
    LightGateInstance *instance = (LightGateInstance*)malloc(sizeof(LightGateInstance));
    memset(instance, 0, sizeof(LightGateInstance));
    instance->gpio_instance = GPIO_Pin;
    instance->Init_state = HAL_GPIO_ReadPin(GPIOC,instance->gpio_instance);
    instance-> now_state = HAL_GPIO_ReadPin(GPIOC,instance->gpio_instance);
    return instance;
}

uint8_t LightGateUpdate(LightGateInstance *instance)
{
    instance->now_state = HAL_GPIO_ReadPin(GPIOC,instance->gpio_instance);
    if(instance->now_state ==1 && instance->Init_state==0)//遮挡到未遮挡
    {
        return 1;
    }
    else if(instance->now_state ==0 && instance->Init_state==1)
    {
        return 2;
    }
    return 0;
}
